<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
$gametype = intval(getvar("gametype"));
$gType = chkGametype($gametype);
switch ($gType)
{
    case 0 :
        $ui = new UI();
        if ($curruser['prev_id'] == 0)
        {
            include( "admin_menu.php" );
        }
        else
        {
            include( "admin_menu1.php" );
        }
        break;
    default :
        include_once( "class_3d/CheckMode_3d.php" );
        $chk = new CheckMode_3d($curruser['acl'], 1, $gametype);
        $chk->checkShow3dPage();
        unset($chk);
        $ui = new UI_3D();
        $jslink = "<script language=\"JScript.Encode\" src=\"site.js\"></script>" . ( "<script language=\"VBScript.Encode\" src=\"site.vbs\"></script>" );
        $ui->set("jslink", $jslink);
        $ui->header();
        include( "admin_menu_3d.php" );
        break;
}
if (isset($_POST['dt']))
{
    $dt1 = split("-", $_POST['dt']);
    if (count($dt1) != 3)
    {
        diemsg("错误的日期格式！");
    }
    if (!checkdate($dt1[1], $dt1[2], $dt1[0]))
    {
        diemsg("不是合理的日期！");
    }
    $dts = $dt1[0] . "-" . ( strlen($dt1[1]) == 1 ? "0" : "" ) . $dt1[1] . "-" . ( strlen($dt1[2]) == 1 ? "0" : "" ) . $dt1[2];
    if (isset($_POST['ok']))
    {
        if (!isset($_POST['users']))
        {
            diemsg("错误的参数！ (" . $_POST['users'] . ")");
        }
        $users = $_POST['users'];
        getdb("update k_user set amount=0,enabled=0 ,updateid=" . $curruser['id'] . ",updatedt='" . systime() . "' where id in (" . $users . ")");
        getdb("update amounts set avail=0,enabled=0 where user_id in (" . $users . ")");
        echo "<p>闲置会员已停用完成!</p>";
    }
    else
    {
        $sql = "select * from k_user where acl=1 and enabled!=0";
        foreach ($g_gametype_3d as $gameid => $val)
        {
            $tbl = $gameid ? "xbet_" . $g_gametype_3d[$gameid]['en'] : "bet";
            $sql .= " and (select count(*) from {$tbl} where user_id=k_user.id)=0";
        }
        $rs = getdb($sql);
        echo "<font color=red><b>闲置会员列表 - </b>最後登入日期 " . $dts . "</font><br>";
        echo "<form action=\"op.php?op=admin&fp=stopmember\" method=post onsubmit=\"this.submit.disabled=true;this.reset.disabled=true\">";
        echo "<table class=table0 border=1 cellpadding=3 cellspacing=0>";
        echo "<tr class=td0><td nowrap>会员帐号<td nowrap>会员名称<td nowrap>盘类<td nowrap>建档/更新日期<td nowrap>最後登入日期";
        $n = "";
        while (!$rs->eof)
        {
            $udt = $rs->f['updatedt'] == "" ? date("Y-m-d", $rs->f['createdt']) : date("Y-m-d", $rs->f['updatedt']);
            $ldt = $rs->f['lastlogdt'] == "" ? $udt : date("Y-m-d", $rs->f['lastlogdt']);
            if ($ldt < $dts)
            {
                echo "<tr class=td2><td nowrap>" . $rs->f['account'];
                echo "<td nowrap>" . $rs->f['name'];
                echo "<td>" . $g_disk_name[$rs->f['disk']];
                echo "<td nowrap>" . $udt;
                echo "<td nowrap>" . ( $rs->f['lastlogdt'] == "" ? "" : date("Y-m-d", $rs->f['lastlogdt']) );
                echo "</td>";
                if ($n != "")
                {
                    $n .= ",";
                }
                $n .= $rs->f['id'];
            }
            $rs->movenext();
        }
        $rs->close();
        echo "</tr></table>";
        if ($n == "")
        {
            echo "<p><font color=red>查无自 " . $dts . " 起闲置的会员!</font></p>";
            echo "<p><input type=button value=放弃 onclick=\"location.href='op.php?op=admin&fp=stopmember&gametype={$gametype}'\">";
        }
        else
        {
            echo "<p>确定停用以上表列会员？</p>";
            echo "<input type=hidden name=dt value='" . $dts . "'>";
            echo "<input type=hidden name=ok value=1>";
            echo "<input type=hidden name=users value='" . $n . "'>";
            echo "<input type=hidden name=gametype value='{$gametype}'>";
            echo "<p><input type=submit value=确定> <input type=button value=放弃 onclick=\"location.href='op.php?op=admin&fp=stopmember&gametype={$gametype}'\">";
        }
        echo "</form>";
    }
}
else
{
    echo "<script src=\"class/calendar/calendar.js\"></script>";
    $dt = date("Y-m-d", systime() - 86400 * 60);
    echo "<font color=red><b>停用闲置会员</b></font><br>";
    echo "<form name=f action=\"op.php?op=admin&fp=stopmember\" method=post onsubmit=\"this.submit.disabled=true;this.reset.disabled=true\">";
    echo "请输入最後登入的日期：<input size=10 name=dt value='" . $dt . "'>&nbsp;&nbsp;";
    echo "<a href=\"javascript:calendar(f.dt)\"><img align=absmiddle src=\"class/calendar/calendar.png\" border=0 alt=\"开启小月历\"></a>";
    echo "<input type=hidden name=gametype value='{$gametype}'>";
    echo "<br><br><input type=submit value=确定>";
    echo "</form>";
}
?>